const generalTools = {
    //计算年龄
    age_(birthday) {
        let age = '';
        if (birthday) {
            let str = birthday.split('-');
            // 新建日期对象
            let date = new Date()
            age = date.getFullYear() - parseInt(str[0])
            let age_month = date.getMonth() + 1 - parseInt(str[1])
            let age_date = date.getDate() - parseInt(str[2])
            if (age > 0) {
                if (age_month < 0) {
                    age -= 1
                } else if (age_month === 0) {
                    if (age_date < 0) {
                        age -= 1
                    }
                }
            }
        }
        return age > 0 ? age : 0;
    },
    returnCode(code){
        switch (code){
            case 400:
                return "语义有误";
            case 401:
                return "服务器认证失败";
            case 403:
                return "服务器拒绝访问";
            case 404:
                return "地址错误";
            case 500:
                return "服务器无响应";
            case 408:
                return "用户另一处登录";
            default:
                return "系统异常"; //其他的状态码则直接打印错误信息
        }
    }
};

export {
    generalTools
}